
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class LinkVenuePlacementTypeComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public LinkVenuePlacementTypeComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public LinkVenuePlacementType SelectOne(int VenuePlacementTypeId)
        {  
			PlacementManager.DAL.LinkVenuePlacementType_DAL o = new PlacementManager.DAL.LinkVenuePlacementType_DAL();
			o.VenuePlacementTypeId = VenuePlacementTypeId;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.LinkVenuePlacementType LinkVenuePlacementTypeToReturn = new PlacementManager.LinkVenuePlacementType((int)row["VenuePlacementTypeId"], (int)row["VenueId"], (int)row["PlacementTypeId"], (bool)row["IsRestricted"], (int)row["MaxNumStudents"], (bool)row["VenueSuppliedEducator"], (bool)row["IsVenueCharge"], (decimal)row["ChargeAmount"], (int)row["VenueChargeTypeId"], (bool)row["IsConfirmedByVenue"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
				return LinkVenuePlacementTypeToReturn;
			}
			else
			{
				PlacementManager.LinkVenuePlacementType LinkVenuePlacementTypeToReturnEmpty = new PlacementManager.LinkVenuePlacementType();
                return LinkVenuePlacementTypeToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkVenuePlacementType> SelectAll(string sortExpression)
        {
            List<LinkVenuePlacementType> listLinkVenuePlacementType = new List<LinkVenuePlacementType>();
            PlacementManager.DAL.LinkVenuePlacementType_DAL o = new PlacementManager.DAL.LinkVenuePlacementType_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listLinkVenuePlacementType.Add(new LinkVenuePlacementType((int)row["VenuePlacementTypeId"], (int)row["VenueId"], (int)row["PlacementTypeId"], (bool)row["IsRestricted"], (int)row["MaxNumStudents"], (bool)row["VenueSuppliedEducator"], (bool)row["IsVenueCharge"], (decimal)row["ChargeAmount"], (int)row["VenueChargeTypeId"], (bool)row["IsConfirmedByVenue"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listLinkVenuePlacementType.Sort(new LinkVenuePlacementTypeComparer(sortExpression));
            return listLinkVenuePlacementType;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkVenuePlacementType> SelectAllWPlacementTypeId(int PlacementTypeId, string sortExpression)
		{
			List<LinkVenuePlacementType> listLinkVenuePlacementType = new List<LinkVenuePlacementType>();
			PlacementManager.DAL.LinkVenuePlacementType_DAL o = new PlacementManager.DAL.LinkVenuePlacementType_DAL();
			o.PlacementTypeId = PlacementTypeId;
			DataSet ds = o.SelectAllWPlacementTypeId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listLinkVenuePlacementType.Add(new LinkVenuePlacementType((int)row["VenuePlacementTypeId"], (int)row["VenueId"], (int)row["PlacementTypeId"], (bool)row["IsRestricted"], (int)row["MaxNumStudents"], (bool)row["VenueSuppliedEducator"], (bool)row["IsVenueCharge"], (decimal)row["ChargeAmount"], (int)row["VenueChargeTypeId"], (bool)row["IsConfirmedByVenue"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listLinkVenuePlacementType.Sort(new LinkVenuePlacementTypeComparer(sortExpression));
			return listLinkVenuePlacementType;
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkVenuePlacementType> SelectAllWVenueId(int VenueId, string sortExpression)
		{
			List<LinkVenuePlacementType> listLinkVenuePlacementType = new List<LinkVenuePlacementType>();
			PlacementManager.DAL.LinkVenuePlacementType_DAL o = new PlacementManager.DAL.LinkVenuePlacementType_DAL();
			o.VenueId = VenueId;
			DataSet ds = o.SelectAllWVenueId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listLinkVenuePlacementType.Add(new LinkVenuePlacementType((int)row["VenuePlacementTypeId"], (int)row["VenueId"], (int)row["PlacementTypeId"], (bool)row["IsRestricted"], (int)row["MaxNumStudents"], (bool)row["VenueSuppliedEducator"], (bool)row["IsVenueCharge"], (decimal)row["ChargeAmount"], (int)row["VenueChargeTypeId"], (bool)row["IsConfirmedByVenue"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listLinkVenuePlacementType.Sort(new LinkVenuePlacementTypeComparer(sortExpression));
			return listLinkVenuePlacementType;
		}


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(LinkVenuePlacementType o)
        {	
            PlacementManager.DAL.LinkVenuePlacementType_DAL oLinkVenuePlacementType = new PlacementManager.DAL.LinkVenuePlacementType_DAL();
			oLinkVenuePlacementType.VenueId = o.VenueId;
			oLinkVenuePlacementType.PlacementTypeId = o.PlacementTypeId;
			oLinkVenuePlacementType.IsRestricted = o.IsRestricted;
			oLinkVenuePlacementType.MaxNumStudents = o.MaxNumStudents;
			oLinkVenuePlacementType.VenueSuppliedEducator = o.VenueSuppliedEducator;
			oLinkVenuePlacementType.IsVenueCharge = o.IsVenueCharge;
			oLinkVenuePlacementType.ChargeAmount = o.ChargeAmount;
			oLinkVenuePlacementType.VenueChargeTypeId = o.VenueChargeTypeId;
			oLinkVenuePlacementType.IsConfirmedByVenue = o.IsConfirmedByVenue;
			oLinkVenuePlacementType.IsActive = o.IsActive;
			oLinkVenuePlacementType.DateCreated = o.DateCreated;
			oLinkVenuePlacementType.CreatedBy = o.CreatedBy;
			oLinkVenuePlacementType.DateUpdated = o.DateUpdated;
			oLinkVenuePlacementType.UpdatedBy = o.UpdatedBy;

            return oLinkVenuePlacementType.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(int VenueId, int PlacementTypeId, bool IsRestricted, int MaxNumStudents, bool VenueSuppliedEducator, bool IsVenueCharge, decimal ChargeAmount, int VenueChargeTypeId, bool IsConfirmedByVenue, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.LinkVenuePlacementType_DAL oLinkVenuePlacementType = new PlacementManager.DAL.LinkVenuePlacementType_DAL();

			oLinkVenuePlacementType.VenueId = VenueId;
			oLinkVenuePlacementType.PlacementTypeId = PlacementTypeId;
			oLinkVenuePlacementType.IsRestricted = IsRestricted;
			oLinkVenuePlacementType.MaxNumStudents = MaxNumStudents;
			oLinkVenuePlacementType.VenueSuppliedEducator = VenueSuppliedEducator;
			oLinkVenuePlacementType.IsVenueCharge = IsVenueCharge;
			oLinkVenuePlacementType.ChargeAmount = ChargeAmount;
			oLinkVenuePlacementType.VenueChargeTypeId = VenueChargeTypeId;
			oLinkVenuePlacementType.IsConfirmedByVenue = IsConfirmedByVenue;
			oLinkVenuePlacementType.IsActive = IsActive;
			oLinkVenuePlacementType.DateCreated = DateCreated;
			oLinkVenuePlacementType.CreatedBy = CreatedBy;
			oLinkVenuePlacementType.DateUpdated = DateUpdated;
			oLinkVenuePlacementType.UpdatedBy = UpdatedBy;

            return oLinkVenuePlacementType.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(LinkVenuePlacementType o)
        {	
            PlacementManager.DAL.LinkVenuePlacementType_DAL oLinkVenuePlacementType = new PlacementManager.DAL.LinkVenuePlacementType_DAL();
			oLinkVenuePlacementType.VenuePlacementTypeId = o.VenuePlacementTypeId;
			oLinkVenuePlacementType.VenueId = o.VenueId;
			oLinkVenuePlacementType.PlacementTypeId = o.PlacementTypeId;
			oLinkVenuePlacementType.IsRestricted = o.IsRestricted;
			oLinkVenuePlacementType.MaxNumStudents = o.MaxNumStudents;
			oLinkVenuePlacementType.VenueSuppliedEducator = o.VenueSuppliedEducator;
			oLinkVenuePlacementType.IsVenueCharge = o.IsVenueCharge;
			oLinkVenuePlacementType.ChargeAmount = o.ChargeAmount;
			oLinkVenuePlacementType.VenueChargeTypeId = o.VenueChargeTypeId;
			oLinkVenuePlacementType.IsConfirmedByVenue = o.IsConfirmedByVenue;
			oLinkVenuePlacementType.IsActive = o.IsActive;
			oLinkVenuePlacementType.DateCreated = o.DateCreated;
			oLinkVenuePlacementType.CreatedBy = o.CreatedBy;
			oLinkVenuePlacementType.DateUpdated = o.DateUpdated;
			oLinkVenuePlacementType.UpdatedBy = o.UpdatedBy;

            return oLinkVenuePlacementType.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int VenuePlacementTypeId, int VenueId, int PlacementTypeId, bool IsRestricted, int MaxNumStudents, bool VenueSuppliedEducator, bool IsVenueCharge, decimal ChargeAmount, int VenueChargeTypeId, bool IsConfirmedByVenue, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.LinkVenuePlacementType_DAL oLinkVenuePlacementType = new PlacementManager.DAL.LinkVenuePlacementType_DAL();

			oLinkVenuePlacementType.VenuePlacementTypeId = VenuePlacementTypeId;
			oLinkVenuePlacementType.VenueId = VenueId;
			oLinkVenuePlacementType.PlacementTypeId = PlacementTypeId;
			oLinkVenuePlacementType.IsRestricted = IsRestricted;
			oLinkVenuePlacementType.MaxNumStudents = MaxNumStudents;
			oLinkVenuePlacementType.VenueSuppliedEducator = VenueSuppliedEducator;
			oLinkVenuePlacementType.IsVenueCharge = IsVenueCharge;
			oLinkVenuePlacementType.ChargeAmount = ChargeAmount;
			oLinkVenuePlacementType.VenueChargeTypeId = VenueChargeTypeId;
			oLinkVenuePlacementType.IsConfirmedByVenue = IsConfirmedByVenue;
			oLinkVenuePlacementType.IsActive = IsActive;
			oLinkVenuePlacementType.DateCreated = DateCreated;
			oLinkVenuePlacementType.CreatedBy = CreatedBy;
			oLinkVenuePlacementType.DateUpdated = DateUpdated;
			oLinkVenuePlacementType.UpdatedBy = UpdatedBy;

            return oLinkVenuePlacementType.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(LinkVenuePlacementType o)
        {
            PlacementManager.DAL.LinkVenuePlacementType_DAL oLinkVenuePlacementType_DAL = new PlacementManager.DAL.LinkVenuePlacementType_DAL();
            oLinkVenuePlacementType_DAL.VenuePlacementTypeId = o.VenuePlacementTypeId;
            return oLinkVenuePlacementType_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int VenuePlacementTypeId)
        {
            PlacementManager.DAL.LinkVenuePlacementType_DAL oLinkVenuePlacementType_DAL = new PlacementManager.DAL.LinkVenuePlacementType_DAL();
            oLinkVenuePlacementType_DAL.VenuePlacementTypeId = VenuePlacementTypeId;
            return oLinkVenuePlacementType_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWPlacementTypeId(int PlacementTypeId)
		{
			PlacementManager.DAL.LinkVenuePlacementType_DAL oLinkVenuePlacementType_DAL = new PlacementManager.DAL.LinkVenuePlacementType_DAL();
			oLinkVenuePlacementType_DAL.PlacementTypeId = PlacementTypeId;			
			return oLinkVenuePlacementType_DAL.DeleteAllWPlacementTypeId();
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWVenueId(int VenueId)
		{
			PlacementManager.DAL.LinkVenuePlacementType_DAL oLinkVenuePlacementType_DAL = new PlacementManager.DAL.LinkVenuePlacementType_DAL();
			oLinkVenuePlacementType_DAL.VenueId = VenueId;			
			return oLinkVenuePlacementType_DAL.DeleteAllWVenueId();
		}

	}
	
	public class LinkVenuePlacementTypeComparer : IComparer<LinkVenuePlacementType>
    {
        private string _sortColumn;
        private bool _reverse;

        public LinkVenuePlacementTypeComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(LinkVenuePlacementType a, LinkVenuePlacementType b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "VenuePlacementTypeId":

			if(a.VenuePlacementTypeId < b.VenuePlacementTypeId)
			{
				retVal = -1;
			}
			else if (a.VenuePlacementTypeId == b.VenuePlacementTypeId)
			{
				retVal = 0;
			}
			else if(a.VenuePlacementTypeId > b.VenuePlacementTypeId)
			{
				retVal = 1;
			}
								break;
				case "VenueId":

			if(a.VenueId < b.VenueId)
			{
				retVal = -1;
			}
			else if (a.VenueId == b.VenueId)
			{
				retVal = 0;
			}
			else if(a.VenueId > b.VenueId)
			{
				retVal = 1;
			}
								break;
				case "PlacementTypeId":

			if(a.PlacementTypeId < b.PlacementTypeId)
			{
				retVal = -1;
			}
			else if (a.PlacementTypeId == b.PlacementTypeId)
			{
				retVal = 0;
			}
			else if(a.PlacementTypeId > b.PlacementTypeId)
			{
				retVal = 1;
			}
								break;
				case "IsRestricted":
					retVal = String.Compare(a.IsRestricted.ToString(), b.IsRestricted.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "MaxNumStudents":

			if(a.MaxNumStudents < b.MaxNumStudents)
			{
				retVal = -1;
			}
			else if (a.MaxNumStudents == b.MaxNumStudents)
			{
				retVal = 0;
			}
			else if(a.MaxNumStudents > b.MaxNumStudents)
			{
				retVal = 1;
			}
								break;
				case "VenueSuppliedEducator":
					retVal = String.Compare(a.VenueSuppliedEducator.ToString(), b.VenueSuppliedEducator.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsVenueCharge":
					retVal = String.Compare(a.IsVenueCharge.ToString(), b.IsVenueCharge.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "ChargeAmount":
					retVal = String.Compare(a.ChargeAmount.ToString(), b.ChargeAmount.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VenueChargeTypeId":

			if(a.VenueChargeTypeId < b.VenueChargeTypeId)
			{
				retVal = -1;
			}
			else if (a.VenueChargeTypeId == b.VenueChargeTypeId)
			{
				retVal = 0;
			}
			else if(a.VenueChargeTypeId > b.VenueChargeTypeId)
			{
				retVal = 1;
			}
								break;
				case "IsConfirmedByVenue":
					retVal = String.Compare(a.IsConfirmedByVenue.ToString(), b.IsConfirmedByVenue.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
